package config

import (
	"log"

	"github.com/spf13/viper"
)

type Config struct {
	App struct {
		Name   string
		Port   string
		Secret string
	}
	Database struct {
		Dsn         string
		MinPoolSize uint64
		MaxPoolSize uint64
	}
	Minio struct {
		Endpoint  string
		AccessKey string
		SecretKey string
		UseSSL    bool
	}
}

var AppConfig *Config

func Init() {
	viper.SetConfigName("config")
	viper.SetConfigType("yml")
	viper.AddConfigPath("./config")
	if err := viper.ReadInConfig(); err != nil {
		log.Fatalf("Error reading config file, %s", err)
	}
	AppConfig = &Config{}
	if err := viper.Unmarshal(AppConfig); err != nil {
		log.Fatalf("Unable to decode into struct, %v", err)
	}
	InitDB()
	InitMinio()
}
